/* GSStocksDetailViewAction.java
 *
 * Project/Product: JZCG-XMBUS
 *
 * Modify Information:
 * =============================================================================
 *   Author	Date       Description
 *   ----------	---------- ---------------------------------------------------
 *   peng.ning	2008-9-23	First release
 *
 * Licensed Materials - Property of APEP
 * =============================================================================
 *    (C) COPYRIGHT Shanghai Auto Mart E-Procurement Co., Ltd. 2007 - 2008
 *    All Rights Reserved.
 *
 *    This software is the confidential and proprietary information of
 *    Shanghai Auto Mart E-Procurement Co., Ltd. ("Confidential Information").
 *    You shall not disclose such Confidential Information and shall use it only
 *    in accordance with the terms of the license agreement you entered into 
 *    with Shanghai Auto Mart E-Procurement Co., Ltd.
 *
 * Noties:
 * =============================================================================
 * 
 */

package com.hitrust.gs.action;

import java.util.ArrayList;

import com.hitrust.gs.business.GSStocksProcesser;
import com.hitrust.gs.lib.GSBaseConstants;
import com.hitrust.gs.service.GSBaseAction;
import com.hitrust.gs.service.GSBaseForm;
import com.hitrust.gs.service.GSBaseManager;
import com.hitrust.gs.util.page.ResultProcess;

public class GSStocksDetailViewAction extends GSBaseAction{
    private GSStocksProcesser sproce=new GSStocksProcesser();
    public String execute(GSBaseForm aForm) throws Exception {
        // TODO Auto-generated method stub
        String deptId=aForm.getRequest().getParameter("deptId");
        String balanceYM=aForm.getRequest().getParameter("balanceYM");
        String[] str={deptId,balanceYM,"1"};
        ArrayList arstocks=sproce.getStocksDetailByMonthProvid(str);
      //取得分页参数
        
        String[] tStr = this.getPageParams(aForm,arstocks.size());
        //执行分页查询
        ArrayList tList = sproce.getStocksDetailByMonthProvidpage(str, Integer.parseInt(tStr[0]),Integer.parseInt(tStr[1]));
        ResultProcess tRsProc = new ResultProcess();
        tRsProc.setResult(tList);
        aForm.getRequest().setAttribute("stocks", tRsProc);
        
        //存储分页参数
        aForm.getRequest().setAttribute("pageSize",tStr[1]);
        aForm.getRequest().setAttribute("totalRecords",tStr[2]);
        
        return GSBaseConstants.FORWARD_SUCCESS;
    }
    private String[] getPageParams(GSBaseForm aForm,int row) throws Exception{
        String tStr[] = new String[3];
        int totalRecords;
        int pageNo;
        int pageSize;
        String tPage = GSBaseConstants.tPage;
        //根据页面传入的查询参数查询订单信息
        if(aForm.getChoice() == null || aForm.getChoice().equals("")){
            totalRecords = row;
            
            // 取得系统默认的页大小
            pageSize = Integer.parseInt(tPage);
            // PageNo=1
            pageNo = 1;
            int n = (totalRecords % pageSize == 0 )? totalRecords / pageSize:totalRecords / pageSize + 1;
            if (pageNo>n) {
                pageNo=n;
            }
            tStr[0] = "" + pageNo;
            tStr[1] = "" + pageSize;
            tStr[2] = "" + totalRecords;
        }else{
            tStr = GSBaseManager.getPageNoAndPageSize(aForm);
        }
        return tStr;
    }
}
